﻿using Autofac.Extensions.DependencyInjection;
using Autofac;
using System.Reflection;

namespace XieCan.Core.Api
{
  public static class AutofacExtension
  {
    public static void AddAutofacExt(this ConfigureHostBuilder host)
    {
      host.UseServiceProviderFactory(new AutofacServiceProviderFactory())
        .ConfigureContainer<ContainerBuilder>(builder =>
        {
          //builder.RegisterAssemblyTypes(typeof(BaseRepository<,,,,>).Assembly)
          //  .AsImplementedInterfaces()
          //  .InstancePerDependency()
          //  .PropertiesAutowired();

          builder.RegisterAssemblyTypes(Assembly.Load("XieCan.Core.Repository"))
            .AsImplementedInterfaces()
            .InstancePerDependency()
            .PropertiesAutowired();
        });
    }
  }
}
